package cn.edu.wfit.modules.directionmanagement.controller;

import java.util.List;

import cn.edu.wfit.modules.directionmanagement.domain.WfitLog;
import cn.edu.wfit.modules.directionmanagement.service.IWfitLogService;
import jakarta.servlet.http.HttpServletResponse;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import cn.edu.wfit.common.log.annotation.Log;
import cn.edu.wfit.common.log.enums.BusinessType;
import cn.edu.wfit.common.security.annotation.RequiresPermissions;

import cn.edu.wfit.common.core.web.controller.BaseController;
import cn.edu.wfit.common.core.web.domain.AjaxResult;
import cn.edu.wfit.common.core.utils.poi.ExcelUtil;
import cn.edu.wfit.common.core.web.page.TableDataInfo;

/**
 * 日志Controller
 * 
 * @author ruoyi
 * @date 2025-09-03
 */
@RestController
@RequestMapping("/log")
public class WfitLogController extends BaseController
{
    @Autowired
    private IWfitLogService wfitLogService;

    /**
     * 查询日志列表
     */
    @RequiresPermissions("system:log:list")
    @GetMapping("/list")
    public TableDataInfo list(WfitLog wfitLog)
    {
//        startPage();
        List<WfitLog> list = wfitLogService.selectWfitLogList(wfitLog);
        return getDataTable(list);
    }

    /**
     * 导出日志列表
     */
    @RequiresPermissions("system:log:export")
    @Log(title = "日志", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, WfitLog wfitLog)
    {
        List<WfitLog> list = wfitLogService.selectWfitLogList(wfitLog);
        ExcelUtil<WfitLog> util = new ExcelUtil<WfitLog>(WfitLog.class);
        util.exportExcel(response, list, "日志数据");
    }

    /**
     * 获取日志详细信息
     */
    @RequiresPermissions("system:log:query")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(wfitLogService.selectWfitLogById(id));
    }

    /**
     * 新增日志
     */
    @RequiresPermissions("system:log:add")
    @Log(title = "日志", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody WfitLog wfitLog)
    {
        System.out.println(wfitLog.toString());
        return toAjax(wfitLogService.insertWfitLog(wfitLog));
    }

    /**
     * 修改日志
     */
    @RequiresPermissions("system:log:edit")
    @Log(title = "日志", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody WfitLog wfitLog)
    {
        return toAjax(wfitLogService.updateWfitLog(wfitLog));
    }

    /**
     * 删除日志
     */
    @RequiresPermissions("system:log:remove")
    @Log(title = "日志", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(wfitLogService.deleteWfitLogByIds(ids));
    }
}
